package routes

import (
	"net/http"

	"github.com/dromara/carbon/v2"
	"github.com/gin-gonic/gin"
	"hyper/supports/helpers"

	"hyper/app/Http/Controllers"
	"hyper/supports/cryption"
	"hyper/supports/langs"
	"hyper/supports/response"
)

func RegisterApiRoute(r *gin.RouterGroup) {
	r.GET("/", func(c *gin.Context) {

		l := helpers.GetLang(c.GetHeader("Accept-Language"))

		time := carbon.Now().String()

		prvkey, pubkey, err := cryption.GenRsaKey()
		if err != nil {
			panic(err.Error())
		}

		response.ResponseException(c, http.StatusOK, langs.VailMsg("paramErr", l), response.D{
			"prv":  prvkey,
			"pub":  pubkey,
			"l":    l,
			"time": time,
		})

	})

	crypt := new(Controllers.BaseController)
	// 加密测试
	r.POST("testEncode", crypt.Encode)
	// 解密测试
	r.POST("testDecode", crypt.Decode)

}
